import Vue from 'vue'
import Router from 'vue-router'
// import store from '../store/store'
import Layout from '../views/layouts/layout.vue'
import home from '../views/Home'
import login from '../views/auth/login.vue'
import menu from '../views/menu/index.vue'
import user from '../views/user'
import roleType from '../views/user/role/type'
import role from '../views/user/role/index'
import setting from '@/views/setting/index'
import base from '@/views/setting/base'
import example from '../views/example/index'
import ueditor from '../views/example/ueditor'
import avatar from '@/views/example/avatar'
import permission from '@/views/permission/index'
import email from '@/views/setting/email'
import smsBase from '@/views/setting/smsBase'
import emailTemplate from '@/views/setting/template'
import payBase from '@/views/setting/pay/base'


// S 人工智能设置

import intelligent from '@/views/setting/intelligent'

// E 人工智能设置

// S 商城  => 店铺管理

import storeShopList from '@/views/store/shop/list'
import storeShopAttest from '@/views/store/shop/attest'

// E 商城 => 上传管理
// S 商城 => 商城管理

import storeMallBasicsettings from '@/views/store/mall/basicsettings'  //基础设置
import storeMallDispatching from '@/views/store/mall/dispatching'
import storeMalType from '@/views/store/mall/type'
import storeOrder from '@/views/store/order/' // 订单管理
import storeTake from '@/views/store/order/take'  // 代发订单
import storeFirm from '@/views/store/firm/'  // 公司介绍
import storeSeckill from '@/views/store/seckill/'
import storeSwipe from '@/views/store/swipe/index'


import storeOfficial from '@/views/store/official/'  //官方商城管理
import storeIntegral from '@/views/store/Integral/' //积分商城

// E 商城 => 商城管理

// S 店铺管理

import management from '@/views/store/management'

// E 店铺管理

// S 设置 => 文件上传

import settingFileUpdate from '@/views/setting/file/update'


// E 设置 => 文件上传

Vue.use(Router)

const routes = [
  {
    path: '/login',
    name: 'login',
    component: login
  },
  {
    path: '/',
    name: 'Layout',
    component: Layout,
    // 嵌套路由
    children: [
      {
        path: '/index',
        name: 'index',
        component: home,
        meta: {
          title: '首页'
        }
      },
      {
        path: '/menu',
        name: 'menu',
        component: menu,
        meta: {
          title: '菜单管理'
        }
      },
      {
        path: '/user/list',
        name: 'user',
        component: user,
        meta: {
          title: '用户管理'
        }
      },
      {
        path: '/role/index',
        name: 'role',
        component: role,
        meta: {
          title: '设置用户组'
        }
      },
      {
        path: 'user/withdraw/',
        component: () =>import("@/views/user/withdraw"),
        meta: {
          title: '用户提现管理'
        }
      },
      {
        path: '/role/type',
        name: 'roleTpye',
        component: roleType,
        meta: {
          title: '用户组分类'
        }
      },
      {
        path: '/setting',
        name: 'setting',
        component: setting,
        meta: {
          title: '系统设置'
        },
        children:[
          {
            path: '/setting/base',
            name: 'base',
            component: base,
            meta: {
              title: '系统设置'
            }
          },
          {
            path: '/setting/email',
            name: 'email',
            component: setting,
            meta: {
              title: '邮件设置'
            },
            children:[
              {
                path: '/setting/email/base',
                name: 'email-base',
                component: email,
                meta: {
                  title: '邮件基础设置'
                }
              },
              {
                path: '/setting/email/template',
                name: 'email-template',
                component: emailTemplate,
                meta: {
                  title: '邮件模板设置'
                }
              },
            ]
          },
          {
            path: '/setting/sms',
            name: 'sms',
            component: setting,
            meta: {
              title: '短信设置'
            },
            children:[
              {
                path: '/setting/sms/base',
                name: 'sms-base',
                component: smsBase,
                meta: {
                  title: '短信基础设置'
                }
              },
            ]
          },
          {
            path: '/setting/pay',
            name: 'pay',
            component: setting,
            meta: {
              title: '支付设置'
            },
            children:[
              {
                path: '/setting/pay/base',
                name: 'pay-base',
                component: payBase,
                meta: {
                  title: '支付基础设置'
                }
              },
            ]
          },
          {
            path: '/setting/file',
            name: 'file',
            component: setting,
            meta: {
              title: '短信设置'
            },
            children:[
              {
                path: '/setting/file/Update',
                name: 'settingFileUpdate',
                component: settingFileUpdate,
                meta: {
                  title: '文件上传设置'
                }
              },
            ]
          },
          {
          path: '/setting',
          component: setting,
          meta: {
            title: '人工智能设置'
          },
          children:[
            {
              path: '/intelligent',
              name: 'intelligent',
              component: intelligent,
              meta: {
                title: '人工智能设置'
              }
            },
          ]
        },
        ]
      },
      {
        path: '/permission',
        name: 'permission',
        component: permission,
        meta: {
          title: '权限设置'
        }
      },
      
      {
        path: '/store',
        name: 'store',
        component: setting,
        meta: {
          title: '商城设置'
        },
        children:[
          {
            path: '/store/official',
            name: 'official',
            component: storeOfficial,
            meta: {
              title: '官方商城管理'
            }
          },
          {
            path: '/store/integral',
            name: 'Integral',
            component: storeIntegral,
            meta: {
              title: '积分商城管理'
            }
          },
          {
            path: '/store/data/list',
            name: 'storeList',
            component: storeShopList,
            meta: {
              title: '店铺列表'
            }
          },
          {
            path: '/store/management',
            name: 'management',
            component: management,
            meta: {
              title: '店铺设置'
            }
          },
          {
            path: '/store/data/attest',
            name: 'storeShopAttest',
            component: storeShopAttest,
            meta: {
              title: '认证管理'
            }
          },
          {
            path: '/store/order',
            name: 'storeOrder',
            component: storeOrder,
            meta: {
              title: '订单管理'
            }
          },
          {
            path: '/store/takeorder',
            name: 'storeOrderTake',
            component: storeTake,
            meta: {
              title: '代发订单'
            }
          },
          {
            path: '/store/firm',
            component: storeFirm,
            meta: {
              title: '公司介绍'
            }
          },
          
          {
            path: '/store/seckill/',
            name: 'storeSeckill',
            component: storeSeckill,
            meta: {
              title: '秒杀管理'
            }
          },
          {
            path: '/store/swipe',
            name: 'storeswipe',
            component: storeSwipe,
            meta: {
              title: '轮播图管理'
            }
          },
          { path: '/store/gift/list', name:'giftList', component: () =>import("@/views/store/gift/list"), meta: {  title: '礼包管理' }  },
          { path: '/store/gift/create', name:'giftCreate', component: () =>import("@/views/store/gift/create"), meta: {  title: '添加礼包' }  },
          { path: '/store/gift/edit/:data', name:'giftEdit', component: () =>import("@/views/store/gift/edit"), meta: {  title: '编辑礼包' }, props: true},
        ]
      },
      {
        path: '/store',
        name: 'storeMall',
        component: setting,
        meta: {
          title: '商城设置'
        },
        children:[
          {
            path: '/store/mall/dispatching',
            name: 'mallDispatching',
            component: storeMallDispatching,
            meta: {
              title: '配送管理'
            }
          },
          {
            path: '/store/mall/basicsettings',
            name: 'mallBasicsettings',
            component: storeMallBasicsettings,
            meta: {
              title: '基础设置'
            }
          },
          {
            path: '/store/mall/type',
            name: 'mallType',
            component:storeMalType,
            meta: {
              title: '商家类型'
            }
          },
        ]
      },
      {
        path: '/example',
        name: 'example',
        component: example,
        meta: {
          title: '示例'
        },
        children:[
          {
            path: '/example/ueditor',
            name: 'ueditor',
            component: ueditor,
            meta: {
              title: '百度富文本编辑器'
            }
          },
          {
            path: '/example/avatar',
            name: 'avatar',
            component: avatar,
            meta: {
              title: '头像上传裁剪'
            }
          },
        ]
      }
    ]
  }
];

const router = new Router({
  routes
});

router.beforeEach((to, from, next) => {
  if (sessionStorage.getItem('accessToken')) {
    next();
  }else{
    if(to.path=='/login'){ //如果是登录页面路径，就直接next()
      next();
    } else { //不然就跳转到登录；
        next('/login');
    }
  }

  // if (to.matched.some(r => r.meta.requiresAuth)) {  // 判断该路由是否需要登录权限
  //   console.log(store.auth.accessToken);
  //   if (store.auth.accessToken) {  // 通过vuex 如果当前有登录
  //     next();
  //   }
  //   else {
  //     console.log("没有登录吖")
  //     next({
  //       path: '/login',
  //       query: {redirect: to.fullPath}
  //     })
  //   }
  // }
  // else {
  //   next();
  // }
});


export default router;